package com.lottery.im.module.service.presenter;

import android.app.Activity;
import com.lottery.im.MyApplication;
import com.lottery.im.api.ApiClient;
import com.lottery.im.api.RetryWithDelay;
import com.lottery.im.api.observer.ShowTipObserver;
import com.lottery.im.api.result.entity.UserInfo;
import com.lottery.im.base.BaseFragmentPresenter;
import com.lottery.im.module.service.view.IntegralView;
import com.trello.rxlifecycle2.LifecycleProvider;
import com.trello.rxlifecycle2.android.FragmentEvent;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.schedulers.Schedulers;
import java.util.concurrent.TimeUnit;

public class IntegralPresenter extends BaseFragmentPresenter<IntegralView>{

  String token = MyApplication.getInstance().getToken();
  String userId = MyApplication.getInstance().getUserInfo().getUserId();

  public IntegralPresenter(Activity activity, IntegralView iView,
      LifecycleProvider<FragmentEvent> provider) {
    super(activity, iView, provider);
  }

  public void queryUserCommonInfo(){
    ApiClient.getApiRetrofitInstance()
        .queryUserCommonInfo(userId,token)
        .throttleFirst(2, TimeUnit.SECONDS)
        //.retryWhen(new RetryWithDelay(100,10000))
        .subscribeOn(Schedulers.io())
        .observeOn(AndroidSchedulers.mainThread())
        .compose(provider.bindToLifecycle())
        .subscribe(new ShowTipObserver<UserInfo>(activity) {
          @Override public void onSuccess(UserInfo userCommonMapBean) {
            iView.loadUserCommonInfoSuccess(userCommonMapBean);
          }
        });
  }
}
